<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>减少数据读取次数</title>
</head>
<body>
    <ul id=’ul‘>
        <li>tom</li>
        <li>10</li>
        <li>coder</li>
    </ul>
    <script>
        var list = document.querySelectorAll('li')
        // function showTxt(ev){
        //     console.log(ev.target.innerHTML)
        // }
        // for(let item of list){
        //     item.onclick = showTxt
        // }
        
        // 事件委托
        var oUl = document.getElementById('ul')
        oUl.addEventListener('click', showTxt, true)
        function showTxt(ev){
            var obj = ev.target
            if(obj.nodeName.toLowerCase()==='li'){
                console.log(obj.innerHTML)
            }
        }
    </script>
</body>
</html>